#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define NUM 32
#define LEN 1024

int main()
{
  char cmd[LEN];
  char* myargv[NUM];
  while(1){
    printf("[lz@instance-lc2dd0zp replace_process]$");
      fgets(cmd, LEN, stdin);
      cmd[strlen(cmd) - 1] = '\0';
      myargv[0] = strtok(cmd, " ");
      int i = 1;
      while(myargv[i] = strtok(NULL, " ")) i++;

    pid_t id = fork();
    if(id == 0){
      //child
      execvp(myargv[0], myargv);
      exit(10);
    }

    int status = 0;
    pid_t ret = waitpid(id, &status, 0);
    if(ret >= 0){
      printf("exit code:%d\n", WEXITSTATUS(status));
    }
    else{
      printf("wait failt\n");
    }
  }
  return 0;
}
